var Online = {
	Detail: {
		init: function() {
			Language.getCurrLanguage();
			Utils.loadJavascriptFile('/application/views/libraries/component/' + language + '.js');
			Utils.loadJavascriptFile('/application/views/libraries/utils/' + language + '.js');
			Utils.loadJavascriptFile('/application/views/module/Online/' + language + '.js');
			Utils.initAjax();
			
			Online.Detail.View.init();
		},
		
		View: {
			dataGridPanelContainer: '',
			
			init: function() {
				Online.Detail.View.dataGridPanelContainer = $('#dataGridPanel #dataGrid');
				Online.Detail.View.DataGrid.init();
			},
			
			DataGrid: {
				gameAreaCombogridLabelContainer: '',
				gameAreaCombogridInputContainer: '',
				searchDateboxLabelContainer: '',
				searchDateboxInputContainer: '',
				searchButtonContainer: '',
				
				init: function() {
					Online.Detail.View.DataGrid.gameAreaCombogridLabelContainer = $('#dataGridPanel #toolbar #gameAreaCombogridLabel');
					Online.Detail.View.DataGrid.gameAreaCombogridInputContainer = $('#dataGridPanel #toolbar #gameAreaCombogridInput');
					Online.Detail.View.DataGrid.searchDateboxLabelContainer = $('#dataGridPanel #toolbar #searchDateboxLabel');
					Online.Detail.View.DataGrid.searchDateboxInputContainer = $('#dataGridPanel #toolbar #searchDateboxInput');
					Online.Detail.View.DataGrid.searchButtonContainer = $('#dataGridPanel #toolbar #searchButton');
					Online.Detail.View.DataGrid.create();
				},
				
				create: function() {
					var width = $(document).width() - 40;
					var height = $(document).height() - 40;
					Online.Detail.View.dataGridPanelContainer.width(width);
					Online.Detail.View.dataGridPanelContainer.height(height);
					Online.Detail.View.dataGridPanelContainer.datagrid({
						fitColumns: false,
						toolbar: '#toolbar',
						columns: [[
							{
								field: 'dateTime',
								title: onlineDetailViewDataGridColumnTitle1,
								width: 150
							},
							{
								field: 'onlineRoleNum',
								title: onlineDetailViewDataGridColumnTitle2,
								width: 80,
							}
						]],
						loadFilter: Utils.dataGridLoadFilter,
						onLoadSuccess: function() {
							Online.Detail.View.Chart.create();
						}
					})
					Component.Combogrid.GameArea.create(
						Online.Detail.View.DataGrid.gameAreaCombogridLabelContainer,
						Online.Detail.View.DataGrid.gameAreaCombogridInputContainer
					);
					Component.Datebox.Search.create(
						Online.Detail.View.DataGrid.searchDateboxLabelContainer,
						Online.Detail.View.DataGrid.searchDateboxInputContainer
					);
					Online.Detail.View.DataGrid.searchButtonContainer.linkbutton({
						iconCls: 'icon-search',
						text: onlineDetailViewDataGridToolbarButtonText1,
					});
					Online.Detail.View.DataGrid.searchButtonContainer.bind(
						'click',
						Online.Detail.View.DataGrid.doSearch
					);
				},
				
				doSearch: function(){
					var gameAreaId = Online.Detail.View.DataGrid.gameAreaCombogridInputContainer.combogrid('getValue');
					var date = Online.Detail.View.DataGrid.searchDateboxInputContainer.datebox('getValue');
					
					Online.Detail.View.dataGridPanelContainer.datagrid({
						url: '/index.php/Online/detail/getListData',
						queryParams: {
							gameAreaId: gameAreaId,
							date: date
						}
					});
				},
			},
			
			Chart: {
				create: function() {
					var gameAreaId = Online.Detail.View.DataGrid.gameAreaCombogridInputContainer.combogrid('getValue');
					var date = Online.Detail.View.DataGrid.searchDateboxInputContainer.datebox('getValue');
					var data = Online.Detail.View.dataGridPanelContainer.datagrid('getData');
					var chartData = [];
					
					for(index = 0; index < data.rows.length; index++) {
						tmp = [];
						tmp.push(data.rows[index].dateTime);
						tmp.push(Number(data.rows[index].onlineRoleNum));
						chartData.push(tmp);
					}
					
					var data = [chartData];
					var startDateTime = date + ' 00:00:00';
					var endDateTime = date + ' 23:59:59';
					var options = {
						axes: {
							xaxis: {
								min: startDateTime,
								max: endDateTime,
								renderer: $.jqplot.DateAxisRenderer,
								tickOptions: {
									formatString: '%#H点'
								},
								tickInterval: 3600
							},
							yaxis: {
								min: 0
							}
						},
						highlighter: {
							show: true,
							lineWidthAdjust: 2.5,
							sizeAdjust: 5,
							showTooltip: true,
							tooltipLocation: 'nw',
							useAxesFormatters: false,
							tooltipAxes: 'y'
						}
					}
					
					var chart = $.jqplot('chart', data, options);
					chart.redraw();
				}
			},
		},
	},

	Summary: {
		init: function() {
			Language.getCurrLanguage();
			Utils.loadJavascriptFile('/application/views/libraries/component/' + language + '.js');
			Utils.loadJavascriptFile('/application/views/libraries/utils/' + language + '.js');
			Utils.loadJavascriptFile('/application/views/module/Online/' + language + '.js');
			Utils.initAjax();
			
			Online.Summary.View.init();
		},
		
		View: {
			dataGridPanelContainer: '',
			
			init: function() {
				Online.Summary.View.dataGridPanelContainer = $('#dataGridPanel #dataGrid');
				Online.Summary.View.DataGrid.init();
			},
			
			DataGrid: {
				freshButtonContainer: '',
				
				init: function() {
					Online.Summary.View.DataGrid.freshButtonContainer = $('#dataGridPanel #toolbar #freshButton');
					Online.Summary.View.DataGrid.create();
				},
				
				create: function() {
					var width = $(document).width() - 40;
					var height = $(document).height() - 40;
					Online.Summary.View.dataGridPanelContainer.width(width);
					Online.Summary.View.dataGridPanelContainer.height(height);
					Online.Summary.View.dataGridPanelContainer.datagrid({
						url: '/index.php/Online/summary/getListData',
						fitColumns: false,
						toolbar: '#toolbar',
						columns: [[
							{
								field: 'operatorName',
								title: onlineSummaryViewDataGridColumnTitle1,
								width: 100,
							},
							{
								field: 'areaNum',
								title: onlineSummaryViewDataGridColumnTitle2,
								width: 60,
							},
							{
								field: 'onlineRoleNum',
								title: onlineSummaryViewDataGridColumnTitle3,
								width: 80,
							},
						]],
						loadFilter: Utils.dataGridLoadFilter,
					}),
					Online.Summary.View.DataGrid.freshButtonContainer.linkbutton({
						iconCls: 'icon-reload',
						text: onlineSummaryViewDataGridToolbarButtonText1,
					});
					Online.Summary.View.DataGrid.freshButtonContainer.bind(
						'click',
						Online.Summary.View.DataGrid.load
					);
				},
				
				load: function() {
					Online.Summary.View.dataGridPanelContainer.datagrid('reload');
				},
			},
		},
	},
}